const connection = require("../app/database");
const dayjs = require("dayjs");
const { v4: uuidv4 } = require("uuid");

class TagService {
  constructor() {
    this.formName = "setting";
  }
  // 编辑
  async update(_params) {
    const { aboutContent, focusContent } = _params;
    return new Promise(async (resolve, reject) => {
      try {
        const statement = `UPDATE ${this.formName} SET aboutContent = ?, focusContent = ? ;`;
        const res = await connection.execute(statement, [aboutContent, focusContent]);
        resolve(res);
      } catch (error) {
        reject(error);
      }
    });
  }
  // 查看
  async info() {
    return new Promise(async (resolve, reject) => {
      try {
        const statement = `
           SELECT * FROM ${this.formName}
         `;
        const [res] = await connection.execute(statement, []);
        if(res.length){
          resolve(res[0]);
        }
        
        resolve(res);
      } catch (error) {
        reject(error);
      }
    });
  }

  // 查看聚焦文章
  async focusBlog() {
    return new Promise(async (resolve, reject) => {
      try {
        const statement = `
           SELECT * FROM blog
         `;
        const [res] = await connection.execute(statement, []);
        resolve(res);
      } catch (error) {
        reject(error);
      }
    });
  }


}

module.exports = new TagService();
